package org.shangma.handler;

import io.seata.core.context.RootContext;
import io.seata.core.exception.TransactionException;
import io.seata.spring.annotation.GlobalTransactional;
import io.seata.tm.api.GlobalTransactionContext;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//@RestControllerAdvice
public class GlobalExceptionHandler {

   //@ExceptionHandler(RuntimeException.class)
    public String handlerException(RuntimeException e){
        if( RootContext.inGlobalTransaction() ){
            try {
                GlobalTransactionContext.reload(RootContext.getXID()).rollback();
            } catch (TransactionException ex) {
                ex.printStackTrace();
            }
        }
        return "XXX";
    }
}
